using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace SaleManagement.Entity.Mapping
{
    public class PostDetailMap : EntityTypeConfiguration<PostDetail>
    {
        public PostDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Subject)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.Sumary)
                .IsRequired();

            this.Property(t => t.Detail)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("PostDetail");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.PostId).HasColumnName("PostId");
            this.Property(t => t.LanguageId).HasColumnName("LanguageId");
            this.Property(t => t.Subject).HasColumnName("Subject");
            this.Property(t => t.Sumary).HasColumnName("Sumary");
            this.Property(t => t.Detail).HasColumnName("Detail");

            // Relationships
            this.HasRequired(t => t.Language)
                .WithMany(t => t.PostDetails)
                .HasForeignKey(d => d.LanguageId);
            this.HasRequired(t => t.Post)
                .WithMany(t => t.PostDetails)
                .HasForeignKey(d => d.PostId);

        }
    }
}
